package org.newcih.activiti.activitiInAction.chapter2;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.newcih.activiti.test.BaseActivitiTest;

public class LeaveTest2 extends BaseActivitiTest {

    @Before
    public void deploy() {
        deploy("activiti/leaveBook.bpmn20.xml");
//        deploy("activiti/leave.bpmn20.xml");
    }

    @Test
    public void testProcess() {
        // 使用内存数据库，创建流程引擎
//        ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
//                .buildProcessEngine();

        // 部署流程定义文件
//        RepositoryService repositoryService = processEngine.getRepositoryService();
//        repositoryService.createDeployment().addClasspathResource("leaveBook.bpmn20.xml").deploy();

        // 验证已部署流程定义
        repositoryService.createProcessDefinitionQuery().list().stream()
                .map(ProcessDefinition::getId)
                .forEach(System.out::println);

        // 启动流程并返回流程实例
        RuntimeService runtimeService = processEngine.getRuntimeService();
        ProcessInstance instance = runtimeService.startProcessInstanceByKey("leaveBook");
//
        Assert.assertNotNull(instance);
//
        System.out.println("pid=" + instance.getId() + ", pdid=" + instance.getProcessDefinitionId());
    }

    @Test
    public void undeploy() {

    }
}
